import subprocess


def pull(folder):
    script = './shell/git-pull.sh'
    try:
        # 执行 Shell 脚本并实时打印输出
        with subprocess.Popen(["bash", script, folder], stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
                              text=True) as process:
            for line in process.stdout:
                print(line.strip())

        # 确保脚本执行完毕
        process.wait()

        if process.returncode != 0:
            raise subprocess.CalledProcessError(process.returncode, process.args)

    except subprocess.CalledProcessError as e:
        print(f"Error: {e}")
    except Exception as e:
        print(f"Unexpected error: {e}")


if __name__ == '__main__':
    repository_folder = '/Users/ryven/Documents/Projects/Java/git-test'
    pull(repository_folder)
